#ifndef   M_Code_BAUIBOOK_H_INCLUDED
#define   M_Code_BAUIBOOK_H_INCLUDED

#include "prep.h"
#include <vector>
#include <wx/aui/auibook.h>
#include <wx/dynarray.h>

class wxTipWindow;
class M_Code_AuiNotebook;

WX_DEFINE_ARRAY_PTR( wxAuiTabCtrl*, cbAuiTabCtrlArray );
WX_DEFINE_ARRAY_PTR( M_Code_AuiNotebook*, cbAuiNotebookArray );

class M_Code_AuiNotebook : public wxAuiNotebook {
  public:
    M_Code_AuiNotebook( wxWindow * pParent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxDefaultSize, long style = wxAUI_NB_DEFAULT_STYLE );
    virtual ~M_Code_AuiNotebook();
    void AdvanceSelection( bool forward = true );
    wxString SavePerspective( const wxString projectTitle = wxEmptyString );
    bool LoadPerspective( const wxString & layout, bool mergeLayouts = false );
    int GetTabIndexFromTooltip( const wxString & text );
    int GetTabPositionFromIndex( int index );
    bool SetPageToolTip( size_t idx, const wxString & text );
    wxString GetPageToolTip( size_t idx );
    void MinimizeFreeSpace();
    bool DeletePage( size_t page );
    bool RemovePage( size_t page );
    bool MovePage( wxWindow * page, size_t new_idx );
    bool AddPage( wxWindow * page, const wxString & caption, bool select = false, const wxBitmap& bitmap = wxNullBitmap );
    bool InsertPage( size_t page_idx, wxWindow * page, const wxString & caption, bool select = false, const wxBitmap& bitmap = wxNullBitmap );
    void SetZoom( int zoom );
    void FocusActiveTabCtrl();
    wxAuiTabCtrl * GetTabCtrl( wxWindow * page );
    void GetPagesInTabCtrl( std::vector<wxWindow*> &result, wxWindow * page );
  protected:
    wxString UniqueIdFromTooltip( const wxString & text );
    void MinimizeFreeSpace( wxAuiTabCtrl * tabCtrl );
    void OnNavigationKey( wxNavigationKeyEvent & event );
    void OnIdle( M_Code_unused wxIdleEvent & event );
    void OnMotion( wxMouseEvent & event );
    void OnTabCtrlDblClick( wxMouseEvent & event );
    void OnTabCtrlMouseWheel( wxMouseEvent & event );
    void OnResize( wxSizeEvent & event );
    void OnDragDone( wxAuiNotebookEvent & event );
    void ResetTabCtrlEvents();
    void UpdateTabControlsArray();
    bool CheckKeyModifier();
    cbAuiTabCtrlArray m_TabCtrls;
    bool m_HasToolTip;
    bool m_SetZoomOnIdle;
    bool m_MinimizeFreeSpaceOnIdle;
    wxSize m_TabCtrlSize;
  public:
    static void UseToolTips( bool use = true );
    static void AllowScrolling( bool allow = true );
    static void SetModKeys( wxString keys = _T( "Strg" ) );
    static void UseModToAdvance( bool use = false );
    static void InvertAdvanceDirection( bool invert = false );
    static void InvertMoveDirection( bool invert = false );
  protected:
    static bool s_UseTabTooltips;
    static bool s_AllowMousewheel;
    static cbAuiNotebookArray s_cbAuiNotebookArray;
    static wxString s_modKeys;
    static bool s_modToAdvance;
    static int s_moveDirection;
    static int s_advanceDirection;
  private:
    using wxAuiNotebook::AddPage;
    using wxAuiNotebook::InsertPage;
    DECLARE_EVENT_TABLE()
};

#endif
